package com.shanghaiyimu.yimiyangche.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.shanghaiyimu.yimiyangche.R;

public class BaoYangActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener,View.OnClickListener{

    private CheckBox dabaoyang,dabaoyang2,dabaoyang3,dabaoyang4,dabaoyang5,dabaoyang6;
    private LinearLayout dabaoyangxianshi,dabaoyangxianshi2,dabaoyangxianshi3,dabaoyangxianshi4,dabaoyangxianshi6,dabaoyangxianshi6w,jiesuan;
    private RelativeLayout rl_baoyangda1q;
    private TextView tianjia,quxiao,qujiesuan;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bao_yang);
        initView();
//        initSetListener();
    }



    private void initView() {
        qujiesuan = (TextView) findViewById(R.id.qujiesuan_tv);
        qujiesuan.setOnClickListener(this);
        jiesuan = (LinearLayout) findViewById(R.id.qqqqq);
        dabaoyangxianshi = (LinearLayout) findViewById(R.id.dabaoyangxianshi);
        dabaoyangxianshi2 = (LinearLayout) findViewById(R.id.dabaoyangxianshi2);
        dabaoyangxianshi3 = (LinearLayout) findViewById(R.id.dabaoyangxianshi3);
        dabaoyangxianshi4 = (LinearLayout) findViewById(R.id.dabaoyangxianshi4);
        dabaoyangxianshi6 = (LinearLayout) findViewById(R.id.dabaoyangxianshi6);
        dabaoyangxianshi6w = (LinearLayout) findViewById(R.id.dabaoyangxianshi6w);
        rl_baoyangda1q = (RelativeLayout) findViewById(R.id.rl_baoyangda1q);
        dabaoyang = (CheckBox) findViewById(R.id.chk_dabaoyang);
        dabaoyang.setOnCheckedChangeListener(this);
        dabaoyang2 = (CheckBox) findViewById(R.id.chk_dabaoyang1);
        dabaoyang2.setOnCheckedChangeListener(this);
        dabaoyang3 = (CheckBox) findViewById(R.id.chk_dabaoyang3);
        dabaoyang3.setOnCheckedChangeListener(this);
        dabaoyang4 = (CheckBox) findViewById(R.id.chk_dabaoyang4);
        dabaoyang4.setOnCheckedChangeListener(this);
        dabaoyang5 = (CheckBox) findViewById(R.id.chk_dabaoyang5);
        dabaoyang5.setOnCheckedChangeListener(this);
        dabaoyang6 = (CheckBox) findViewById(R.id.chk_dabaoyang6);
        dabaoyang6.setOnCheckedChangeListener(this);
//        dabaoyang.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                if (isChecked){
//                    dabaoyangxianshi.setVisibility(View.VISIBLE);
//                }else {
//                    dabaoyangxianshi.setVisibility(View.GONE);
//                }
//            }
//        });
        tianjia = (TextView) findViewById(R.id.tianjia);
        tianjia.setOnClickListener(this);
        quxiao = (TextView) findViewById(R.id.jianshao);
        quxiao.setOnClickListener(this);




    }


    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (dabaoyang.isChecked()||dabaoyang2.isChecked()||dabaoyang3.isChecked()||dabaoyang4.isChecked()||dabaoyang5.isChecked()||dabaoyang6.isChecked()){
            jiesuan.setVisibility(View.VISIBLE);
        }else {
            jiesuan.setVisibility(View.GONE);
        }
        switch (buttonView.getId()){
            case R.id.chk_dabaoyang:
                if (isChecked){
                    dabaoyangxianshi.setVisibility(View.VISIBLE);
                }else {
                    dabaoyangxianshi.setVisibility(View.GONE);
                }
            break;
            case R.id.chk_dabaoyang1:
                if (isChecked){
                    dabaoyangxianshi2.setVisibility(View.VISIBLE);
                }else {
                    dabaoyangxianshi2.setVisibility(View.GONE);
                }
                break;
            case R.id.chk_dabaoyang3:
                if (isChecked){
                    dabaoyangxianshi3.setVisibility(View.VISIBLE);
                }else {
                    dabaoyangxianshi3.setVisibility(View.GONE);
                }
                break;
            case R.id.chk_dabaoyang4:
                if (isChecked){
                    dabaoyangxianshi4.setVisibility(View.VISIBLE);
                }else {
                    dabaoyangxianshi4.setVisibility(View.GONE);
                }
                break;
            case R.id.chk_dabaoyang5:
                if (isChecked){
                    dabaoyangxianshi6.setVisibility(View.VISIBLE);
                }else {
                    dabaoyangxianshi6.setVisibility(View.GONE);
                }
                break;
            case R.id.chk_dabaoyang6:
                if (isChecked){
                    dabaoyangxianshi6w.setVisibility(View.VISIBLE);
                }else {
                    dabaoyangxianshi6w.setVisibility(View.GONE);
                }
                break;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            // 添加1L
            case R.id.tianjia:
                rl_baoyangda1q.setVisibility(View.VISIBLE);
                tianjia.setVisibility(View.GONE);
                quxiao.setVisibility(View.VISIBLE);
                break;
            // 取消添加
            case R.id.jianshao:
                rl_baoyangda1q.setVisibility(View.GONE);
                quxiao.setVisibility(View.GONE);
                tianjia.setVisibility(View.VISIBLE);
                break;
            case R.id.qujiesuan_tv:
                startActivity(new Intent(BaoYangActivity.this,DingDanBaoYangActivity.class));
                break;
        }
    }
}
